package partes_GUI.Stats_GUI;
import javax.swing.JLabel;

import partes_GUI.PanelGeneral;

public class StatsPanel extends PanelGeneral {

	private static final long serialVersionUID = -6196647248777728056L;
	
	private static final int labelAlto=20;
	private static final int labelAncho=75;	
	private int base;
	private int altura;
	
	private StatTF[] stats;
	
	public StatsPanel(StatComponentFactory f) {
		super();
		int X=marco*2+labelAncho+20;
		int Y=marco*2-sep;
		int i=0;
		stats= new StatTF[f.ids().length];
		for(Object st: f.ids()){
			JLabel laux = new JLabel(st.toString());				
			this.add(laux);
			laux.setBounds(marco,
							marco+(sep+labelAlto)*i,
							labelAncho,
							labelAlto);
			Y+=labelAlto+sep;
			StatTF[] taux= f.crearStatTFs();
			for (StatTF tf: taux){
				this.add(tf);
			}
			taux[0].ubicar(marco+sep+labelAncho,
							marco+(sep+labelAlto)*i);
			stats[i]=taux[0];
			StatScrollBar sbaux= f.crearStatScrollBar();
			if (sbaux!=null){
				this.add(sbaux);
				sbaux.setBounds(marco+labelAncho+taux[0].getAncho()+sep,
								marco+(sep+labelAlto)*i,
								20, 
								labelAlto);
				sbaux.setCampos(taux);
				for (int c=1;c<taux.length;c++){					
					taux[c].ubicar(marco+labelAncho+sep+taux[0].getAncho()+sbaux.getHeight()+sep+(c-1)*(10+taux[c].getAncho()),
									marco+(sep+labelAlto)*i);
				}
			}
			i++;	
		}
		for (StatTF s:f.crearStatTFs())
			X+=s.getAncho()+sep;
		StatScrollBar sbaux= f.crearStatScrollBar();
		if (sbaux!=null)
			X+=sbaux.getHeight();
		base=X;
		altura=Y;
	}
	
		
	public int[] getStats(){
		int[] aux= new int[stats.length];
		for(int i=0;i<stats.length;i++)
			aux[i]=Integer.parseInt(stats[i].getText());
		return aux; 
	}

	public void Ubicar(int X, int Y){
		this.setBounds(X, Y, base, altura);
	}
	
}
